import 'const.dart';
import 'ffi.dart';
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:ui' show window;
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:kraken/devtools.dart';
import 'package:kraken/kraken.dart';

void main() async {
  runApp(Init());
}

class Init extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // 设置顶部状态栏颜色
    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
        statusBarColor: Color(0x00ffffff),
        statusBarIconBrightness: Brightness.dark));
    final screen = MediaQueryData.fromWindow(window);

    return MaterialApp(
        title: 'rmw.link',
        theme: ThemeData(),
        home: Container(
            decoration: BoxDecoration(color: Colors.white),
            padding: EdgeInsets.only(top: screen.padding.top),
            // 多个可以这样 future: Future.wait([platform, isRelease]),

            child: FutureBuilder(
                future: Future.wait([api.platform(), api.rustReleaseMode()]),
                builder: (context, snap) {
                  if (snap.error != null) {
                    // An error has been encountered, so give an appropriate response and
                    // pass the error details to an unobstructive tooltip.
                    final err = snap.error.toString();
                    debugPrint(err);
                    return Tooltip(
                      message: err,
                    );
                  }
                  final data = snap.data;
                  if (data == null) return const CircularProgressIndicator();

                  debugPrint(data.toString());

                  final kraken = Kraken(
                    bundle: KrakenBundle.fromUrl('assets:dist/m.js'),
                    devToolsService: isDev ? ChromeDevToolsService() : null,
                    background: Colors.white,
                  );
                  return kraken;
                })));
  }
}
